<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core_1_1" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a href="${applicationScope.basePath}/home" class="navbar-brand">二手交易平台</a>
        </div>
        <div class="navbar-collapse collapse">

            <c:if test="${empty sessionScope.activeUser}">
                <ul id='main_menu' class="nav navbar-nav navbar-right">
                    <li><a href="${applicationScope.basePath}/login"
                           onclick="change_main_menu('xxx');return false;">登陆</a></li>
                    <li><a href="${applicationScope.basePath}/register" target="_blank">注册</a></li>
                </ul>
            </c:if>
            <c:if test="${!empty sessionScope.activeUser}">
                <ul id='main_menu' class="nav navbar-nav navbar-right">
                    <li><a href="${applicationScope.basePath}/home"><span class="glyphicon glyphicon-home"></span>&nbsp;&nbsp;首页</a>
                    </li>
                    <li><a id="shop_cart" href="${applicationScope.basePath}/shopcart/mycart"><span
                            class="glyphicon glyphicon-shopping-cart"></span>&nbsp;&nbsp;购物车<span id="cart_num"
                                                                                                  class="num_span">0</span></a>
                    </li>
                    <li><a id="category" href="${applicationScope.basePath}/goods/category"><span class="glyphicon glyphicon-tag"></span>&nbsp;&nbsp;商品分类</a></li>
                    <li><a id="publish" href="${applicationScope.basePath}/goods/publishGoods"><span
                            class="glyphicon glyphicon-list-alt"></span>&nbsp;&nbsp;发布商品</a></li>
                    <li><a id="person" href="${applicationScope.basePath}/user/space"><span class="glyphicon glyphicon-user"></span>&nbsp;&nbsp;个人中心</a></li>
                    <li><a href="${applicationScope.basePath}/user/logout"><span class="glyphicon glyphicon-off"></span>&nbsp;&nbsp;退出</a>
                    </li>
                </ul>
            </c:if>
        </div>
    </div>
</nav>

<script>

    $(document).ready(function () {
        let path = window.location.href;
        let data = '{"uri":"'+ path +'"}';
        $.ajax({
            url: "${applicationScope.basePath}/look",
            type: "POST",
            dataType: "json",
            contentType: "application/json;charset=UTF-8",
            data:data
        });
    });

    <c:if test="${!empty sessionScope.activeUser}">
    $(function () {
        $.ajax({
            url: "${applicationScope.basePath}/shopcart/num",
            type: "GET",
            dataType: "json",
            contentType: "application/json;charset=UTF-8",
            success: function (data) {
                $("#cart_num").text(data.datas);
            }
        });
    });
    </c:if>
</script>
</body>
</html>
